package com.asiainfo.product.controller;

import com.asiainfo.entity.product.Product;
import com.asiainfo.product.service.ProductService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/product")
public class ProductController {

    @Autowired
    ProductService productService;

    //定义返回商品的接口
    @GetMapping("/product/{id}") //从请求路径获取参数
    public Product getProductById(@PathVariable("id") Long productId,
//                                  @RequestHeader("Token") String token3,
                                  HttpServletRequest httpServletRequest) {
        String token = httpServletRequest.getHeader("Token");
//        log.info("调用product-server,token，{},token2:{}",token,token3);


//        int result=10/0;
        Product product = productService.getProductById(productId);
        return product;
    }
}
